<%@ taglib prefix="s" uri="/jodd" %>
<%@ taglib prefix="t" uri="/easyui-tags" %>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="org.jeecgframework.web.util.StaticValue" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>CSA新建发货单</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
    <script type="text/javascript">
        //编写自定义JS代码
        $(document).ready(function () {

            addEquipment();

            /*
            * 获取省份
            * */
            $.ajax({
                type: "post",
                url: "cbsWarehouseController.do?getProvince",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择省份--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].territoryCode + '>' + tbs[i].territoryName + '</option>';
                    }
                    $("#sheng").html(html);
                    $("#thSheng").html(html);

                }
            });

            /*
            * 获取发货单类型
            * */
            $.ajax({
                type: "post",
                url: "cbsDelinerController.do?getDeliverType",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择发货单类型--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].typecode + '>' + tbs[i].typename + '</option>';
                    }
                    $("#deliverType").html(html);
                }
            });

            /*
            * 获取发货SLA
            * */
            $.ajax({
                type: "post",
                url: "cbsDelinerController.do?getSendSLA",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择发货SLA--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].typecode + '>' + tbs[i].typename + '</option>';
                    }
                    $("#sendSLA").html(html);
                }
            });

            /*
            * 获取库位
            * */
            $.ajax({
                type: "post",
                url: "cbsDelinerController.do?getKuWei",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择库位--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].typecode + '>' + tbs[i].typename + '</option>';
                    }
                    $("#warehouseLocaltion").html(html);
                }
            });


            /*
            * 获取服务单信息
            * */
            /*$.ajax({
                type:"GET",
                url:"cbsDelinerController.do?getServiceCode",
                dataType:"json",
                success:function (data) {
                    var tbs = data.obj;
                    var  html = "<option value=''>--请选择服务单号--</option>";
                    for (i in tbs){
                        html += '<option  value='+tbs[i].id+'>'+tbs[i].code+'</option>';
                    }
                    //$("#crCode").html(html);

                }
            })*/

            /*
            * 获取全部物流信息
            * */
            $.ajax({
                type: "post",
                url: "cbsDelinerController.do?getLogistics",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择物流--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].departname + '>' + tbs[i].departname + '</option>';
                    }
                    // $("#deliverLogistics_id").html(html);
                    $("#retrun_logistics").html(html);

                }
            })

        })

        function isReturn(obj) {
            var uuid = obj.id.substring(0, 32);
            var id = obj.value;
            $.ajax({
                type: "post",
                data: {"id": id},
                url: "cbsDelinerController.do?getIsReturnByItem",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    //alert("tbs:"+tbs.isReturn)
                    if (tbs.isReturn == 1) {
                        $('#' + uuid + 'isReturn').val(2)
                    } else {
                        $('#' + uuid + 'isReturn').val(1)
                    }
                }
            })
        }

        function getAllTypes() {

            /*
            * 获取优先级
            * */
            $.ajax({
                type: "post",
                url: "cbsDelinerController.do?getApplyLayer",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].typecode + '>' + tbs[i].typename + '</option>';
                    }
                    console.log("tbs:" + tbs)
                    $(".applyLayer").html(html);
                }
            })
        }

        /*
        * 获取收货地址城市
        * */
        function getCity() {
            var province = $("#sheng").val();
            $.ajax({
                type: "post",
                data: {"code": province},
                url: "cbsWarehouseController.do?getCity",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择城市--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].id + '>' + tbs[i].territoryName + '</option>';
                    }
                    $("#city").html(html);

                }
            })
        }


        /*
        * 获取提货城市
        * */
        function getThCity() {
            var province = $("#thSheng").val();
            $.ajax({
                type: "post",
                data: {"code": province},
                url: "cbsWarehouseController.do?getCity",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择城市--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].id + '>' + tbs[i].territoryName + '</option>';
                    }
                    $("#thCity").html(html);

                }
            })
        }

        function getSelectedWarouse() {
            var deliverLogistics_id = $("#deliverLogistics_id").val();
            var cityId = $("#city").val();
            // alert(cityId+"----"+deliverLogistics_id);
            if (cityId != "" && deliverLogistics_id != "0") {
                $.ajax({
                    type: "post",
                    data: {"cityCode": cityId, "logistics": deliverLogistics_id},
                    url: "cbsDelinerController.do?getWarehouseByLogisticsForCity",
                    dataType: "json",
                    success: function (data) {
                        var obj = data.obj;
                        $('#deliverWarehouseId option').each(function () {
                            if ($(this).val() == obj[0].id) {
                                $(this).attr("selected", true);
                            }
                        })
                    }
                })
            }
        }

        /*
        * 根据收货城市获取推荐物流
        * */
        function getLogisticsByCity() {

            var city = $("#city").val();
            // alert(city);
            $.ajax({
                type: "post",
                data: {"code": city},
                url: "cbsDelinerController.do?getLogisticsByCity",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "";
                    if (tbs == null || tbs == "" || tbs == undefined) {

                        $("#logisticsSLA").text("无");
                        $("#deliverLogistics_id option:first").prop("selected", 'selected');
                        getFhContacts();
                        getWarehouseByLogistics();
                        // $("#warehouseContacts").html('<label>暂无联系人信息</label>');
                    } else {

                        $('#deliverLogistics_id option').each(function () {
                            if ($(this).text() == tbs[0].logistics) {
                                $(this).attr("selected", true);
                            }
                        })
                        $("#logisticsSLA").text(tbs[0].slaType);
                        getWarehouseByLogistics();
                        getFhContacts();
                    }

                }
            })

            // getSLA();
        }

        /*
        * 获取仓库联系人
        * */
        function getWarehouseContacts() {

            var deliverWarehouseId = $("#deliverWarehouseId").val();
            // alert(deliverWarehouseId)
            if (deliverWarehouseId == "0") {
                $("#warehouseContacts").html('<label>暂无联系人信息</label>');
            } else {
                $.ajax({
                    type: "post",
                    data: {"code": deliverWarehouseId},
                    url: "cbsDelinerController.do?getWarehouseContacts",
                    dataType: "json",
                    success: function (data) {
                        var tbs = data.obj;
                        var name = tbs.userName;
                        var phone = tbs.phone;
                        var email = tbs.email;

                        if (tbs.userName == null) {
                            name = "";
                        }
                        if (tbs.phone == null) {
                            phone == "";
                        }
                        if (tbs.email == null) {
                            email == "";
                        }
                        if (tbs.email == null && tbs.userName == null && tbs.phone == null) {
                            html = '<label>暂无联系人信息</label>';
                        } else {
                            html = '<label>' + name + '&nbsp &nbsp ' + phone + '&nbsp &nbsp' + email + '</label>';
                        }
                        $("#warehouseContacts").html(html);
                        console.log("contects:" + tbs)
                    }

                })
            }

        }

        /*
        * 根据返件物流获取联系人
        * */
        function getContacts() {
            var logisticsName = $("#retrun_logistics").val();
            //alert(logisticsName)
            $.ajax({
                type: "post",
                data: {"code": logisticsName},
                url: "cbsDelinerController.do?getContacts",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    //alert("tbs:"+tbs);
                    var html;
                    if (tbs == null || tbs == "") {
                        //alert("暂无联系人信息");
                        html = '<label>联系人:暂无联系人信息</label>';
                    } else {
                        html = '<label>联系人:' + tbs.name + '&nbsp &nbsp ' + tbs.cellphone1 + '&nbsp &nbsp' + tbs.email + '</label>';
                    }
                    $("#retrunLogisticsContacts").html(html);
                }

            })
        }

        function getWarehouseByLogistics() {

            var city = $("#city").val();
            var logistics = $("#deliverLogistics_id").val();
            if (logistics == "0") {
                getCang();
            } else {
                $.ajax({
                    type: "post",
                    data: {"cityCode": city, "logistics": logistics},
                    url: "cbsDelinerController.do?getWarehouseByLogistics",
                    dataType: "json",
                    success: function (data) {
                        var tbs = data.obj;

                        if (tbs == null) {
                            $("#deliverWarehouseId").html("<option value=''>--请选择仓库--</option>");
                            $("#warehouseContacts").html('暂无联系人');
                        } else {
                            var html = "<option value='0'>--请选择仓库--</option>";
                            for (i in tbs) {
                                html += "<option value='" + tbs[i].id + "'>" + tbs[i].name + "</option>";

                            }
                            $("#deliverWarehouseId").html(html);
                            var cityId = $("#city").val();
                            if (cityId != "") {
                                $.ajax({
                                    type: "post",
                                    data: {"cityCode": cityId, "logistics": logistics},
                                    url: "cbsDelinerController.do?getWarehouseByLogisticsForCity",
                                    dataType: "json",
                                    success: function (data) {
                                        var obj = data.obj;
                                        $('#deliverWarehouseId option').each(function () {
                                            if ($(this).val() == obj[0].id) {
                                                $(this).attr("selected", true);
                                            }
                                        })
                                        getWarehouseContacts();
                                    }
                                })
                            }
                            // $("#warehouseContacts").html('<label>'+tbs[0].userName+'&nbsp &nbsp '+tbs[0].phone+'&nbsp &nbsp'+tbs[0].email+'</label>')

                        }
                        // getFhContacts();
                        getWarehouseContacts();
                    }
                })
            }

        }

        function getCang() {

            var cityId = $("#city").val();
            var logistics = $("#deliverLogistics_id").val();
            $.ajax({
                type: "post",
                data: {"cityCode": cityId, "logistics": logistics},
                url: "cbsDelinerController.do?getWarehouseByLogistics",
                dataType: "json",
                success: function (data) {
                    var obj = data.obj;
                    // $('#deliverWarehouseId option').each(function(){
                    //     if($(this).val()==obj[0].id ){
                    //         $(this).attr("selected",true);
                    //     }
                    // })
                    var html = "<option value='0'>--请选择仓库--</option>";
                    for (i in obj) {
                        html += "<option value='" + obj[i].id + "'>" + obj[i].name + "</option>";
                    }
                    $("#deliverWarehouseId").html(html);
                    getWarehouseContacts();
                }
            })
        }

        function getSLA() {
            var logisticsName = $("#deliverLogistics_id").val();
            var cityId = $("#city").val();
            if (logisticsName != "" || logisticsName != null) {
                $.ajax({
                    type: "post",
                    data: {"logisticsName": logisticsName, "cityId": cityId},
                    url: "cbsDelinerController.do?getSLA",
                    dataType: "json",
                    success: function (data) {
                        var obj = data.obj;
                        if (obj == null) {
                            $("#logisticsSLA").text("无");
                        }
                        if (obj != null) {
                            var slaType = obj.slaType;
                            $("#logisticsSLA").text(slaType);
                        }
                    }
                })
            }
        }

        function getSLAByWarsoue() {
            var logisticsName = $("#deliverLogistics_id").val();
            var cityId = $("#city").val();
            var deliverWarehouseId = $("#deliverWarehouseId").val();
            if (logisticsName != "" || logisticsName != null) {
                $.ajax({
                    type: "post",
                    data: {"logisticsName": logisticsName, "cityId": cityId, "deliverWarehouseId": deliverWarehouseId},
                    url: "cbsDelinerController.do?getSLAByWarouse",
                    dataType: "json",
                    success: function (data) {
                        var obj = data.obj;
                        if (obj == null) {
                            $("#logisticsSLA").text("无");
                        }
                        if (obj != null) {
                            var slaType = obj.slaType;
                            $("#logisticsSLA").text(slaType);
                        }
                    }
                })
            }
        }

        function getFhContacts() {
            var logisticsName = $("#deliverLogistics_id").val();

            if (logisticsName != "") {
                $.ajax({
                    type: "post",
                    data: {"code": logisticsName},
                    url: "cbsDelinerController.do?getContacts",
                    dataType: "json",
                    success: function (data) {
                        var tbs = data.obj;
                        //alert("tbs:"+tbs);
                        var html;
                        if (tbs == null || tbs == "") {
                            //alert("暂无联系人信息");
                            html = '<label>暂无联系人信息</label>';
                        } else {
                            html = '<label>' + tbs.name + '&nbsp &nbsp ' + tbs.cellphone1 + '&nbsp &nbsp' + tbs.email + '</label>';
                        }
                        $("#fhLogisticsContacts").html(html);
                    }
                })
            }

        }

        /*
        *
        * */
        function addEquipment() {
            $.ajax({
                url: "cbsDelinerController.do?getUuid",
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                    parent.window.tip("添加备件失败");
                },
                success: function (uuid) {
                    var html = '<table class="nobordertable noborder" id="' + uuid + 't" style="border: none;">' +
                        '<tbody><tr><td class="al_r" width="20%"><label>备件类型:<font color="red">*</font></label></td><td width="30%">' +
                        '<input name="uuidName" type="hidden" value="' + uuid + '" />' +
                        '<input name="typeId" type="hidden" id="' + uuid + '" />' +
                        '<input class="inputxt" name="typeDes" id="' + uuid + 'typeDes"  readonly="readonly" uuid="*" />&nbsp;&nbsp;' +
                        '<input class="button" value="请选择" type="button" id="' + uuid + '" onclick="getTree(this,null)"/>&nbsp;<span hidden="hidden" id="' + uuid + 'typeDesErr" style="color: red;font-size: 10px">备件类型不能为空</span>' +
                        '</td><td class="al_r" width="20%">' +
                        '<label>备件号:<font color="red">*</font></label></td><td width="30%"><span><select name="itemId" id="' + uuid + 'itemId" onchange="isReturn(this);checkeNull(this)"><option value="">--请选择备件号--</option></select><input name="item" id="' + uuid + 'in"  type="text" onkeyup="hideItemErr(this)" hidden="hidden">' +
                        '&nbsp;<span hidden="hidden" id="' + uuid + 'itemIdErr" style="color: red;font-size: 10px">备件号不能为空</span></td>' +
                        '</tr><tr><td class="al_r" width="20%"><label>数量:<font color="red">*</font></label></td>' +
                        '<td width="30%"><input id="' + uuid + 'total" name="total" onkeyup="checkeNull(this)" />&nbsp;<span hidden="hidden" id="' + uuid + 'totalErr" style="color: red;font-size: 10px">备件数量不能为空或0</span></td>' +
                        '<td class="al_r" width="20%"><label>是否返件:</label></td><td width="30%"><select id="' + uuid + 'isReturn" name="isReturn"><option value="1">否</option><option value="2">是</option></select></td></tr>' +
                        '<tr><td class="al_r" width="20%"><label>备件序列号:</label></td>' +
                        '<td width="30%"><input name="sn" id="sn"/></td>' +
                        '<td class="al_r" width="20%"><label>申请理由:</label></td>' +
                        '<td><t:dictSelect clazz="noSelect" hasPleaseSelect="false" readonly="false" field="applyReason"  type="select" typeGroupCode="<%=StaticValue.apply_reason%>"/></td>' +
                        '</tr><tr><td class="al_r" width="20%"><label>申请优先级:</label></td>' +
                        '<td width="30%"><t:dictSelect clazz="noSelect" hasPleaseSelect="false" readonly="false" field="applyLayer"  type="select" typeGroupCode="<%=StaticValue.apply_layer%>"/></td>' +
                        '<td class="al_r" width="20%"><label>备件描述:</label></td>' +
                        '<td><textarea name="memo"  id="memo" cols="30" rows="3" maxlength="200"></textarea></td></tr>' +
                        '</tbody></table><div style="text-align:center">' +
                        '<div style="text-align:center"><a href="#" class="easyui-linkbutton l-btn" onclick=delSparePart("' + uuid + '",this)><span class="l-btn-left"><span class="l-btn-text">删除</span></span></a></div>' +
                        '<div class="line" id="' + uuid + 'l" ></div>';
                    $("#addEquipmentDiv").prepend(html);
                    getAllTypes();
                }
            });
        }

        function getTree(obj, id) {
            var uuid = obj.id;
            $.dialog({
                content: "url:cbsDelinerController.do?goChooseEquipmentType&uuid=" + uuid + "&id=" + id,
                zIndex: 2100,
                title: '机型',
                lock: true,
                width: '300px',
                height: '400px',
                left: '55%',
                top: '65%',
                opacity: 0.4,
                init: function () {
                    top.myWindow = window;
                },
            });
        }

        function delSparePart(uuid, obj) {
            $("#" + uuid + "t").remove();
            $("#" + uuid + "l").remove();
            $(obj).remove();
        }

        /*新建发货单发货方法*/
        function addDeliver() {
            //发货单字段数据
            var srCode = $('#srCode').val();   //SR
            var soCode = $('#soCode').val();   //SO
            var crCode = $('#crCode').val();  //CR(CBS服务单号)
            var deliverType = $('#deliverType').val();    //发货单类型
            var zt = $('#isZt input[name="zt"]:checked ').val();     //是否自提
            var userName = $('#userName').val();  //收货人姓名
            var phone = $('#phone').val();  //收货人电话
            var fhSheng = $('#sheng').val();   //收货人所在省
            var fhShi = $('#city').val();  //收货人所在市
            var address = $('#address').val();  //收货地址
            var cinemaName = $('#cinemaName').val();     //影院
            var deliverLogisticsId = $('#deliverLogistics_id').val();  //发货物流
            var delinerWarehouseId = $('#deliverWarehouseId').val();  //发货所在仓库
            var deliverDes = $('#deliverDes').val();   //发货说明
            var retrunLogistics = $('#retrun_logistics').val(); //返件物流
            var ztWarehouseId = $('#warehouse').find("option:selected").val(); //自提仓库
            var thProvince = $('#thSheng').val(); //提货省
            var thShi = $('#thCity').val(); //提货市
            var addressTh = $('#thAddress').val(); //提货具体地址
            var warehouseLocaltion = $('#warehouseLocaltion').val(); //库位
            var sendSLA = $('#sendSLA').val(); //发货sla
            var wlSla = $('#logisticsSLA').text();

            // so 非必填
            // if (soCode == null || soCode == '') {
            //     parent.window.tip("请填写SO号")
            //     $('#soCodeErr').show();
            //     return false;
            // }

            if (deliverType == null || deliverType == '') {
                $('#deliverTypeErr').show();
                parent.window.tip("请选择发货单类型")
                return false;
            }

            var typeNull = true;
            var itemNull = true;
            var totalNull = true;
            var equipment = [];
            $('#addEquipmentDiv table').each(function () {
                var obj = {};
                obj.uuid = $(this).find('input[name="uuidName"]').val();
                obj.equipmentType = $(this).find('input[name="typeId"]').val();
                obj.itemId = $(this).find('select[name="itemId"] option:selected').val();
                obj.item = $(this).find('input[name="item"]').val();
                obj.total = $(this).find('input[name="total"]').val();
                obj.isReturn = $(this).find('select[name="isReturn"] option:selected').val();
                obj.applyReason = $(this).find('select[name="applyReason"] option:selected').val();
                obj.applyLayer = $(this).find('select[name="applyLayer"] option:selected').val();
                obj.sn = $(this).find('input[name="sn"]').val();
                obj.memo = $(this).find('textarea[name="memo"]').val();
                equipment.push(obj)
                console.log("obj:" + obj.uuid);
                console.log("equipmentType:" + obj.equipmentType);
                console.log("itemId:" + obj.itemId);
                console.log("total:" + obj.total);
                console.log("item:" + obj.item);
                var uuid = obj.uuid;
                if (obj.equipmentType == null || obj.equipmentType == '') {
                    $('#' + uuid + 'typeDesErr').show()
                    typeNull = false;

                }
                if (obj.itemId == null || obj.itemId == '') {
                    if (obj.item == null || obj.item == '') {
                        $('#' + uuid + 'itemIdErr').show()
                        itemNull = false;
                    }

                }
                if (obj.total == null || obj.total == '' || obj.total == 0) {
                    $('#' + uuid + 'totalErr').show()
                    totalNull = false;

                }
                //alert("obj:"+equipment);
            });
            if (typeNull == false) {
                parent.window.tip("请选择备件类型")
                return false;
            }
            if (itemNull == false) {
                parent.window.tip("请选择备件号")
                return false;
            }
            if (totalNull == false) {
                parent.window.tip("请填写备件数量")
                return false;
            }

            if (userName == null || userName == '') {
                $('#userNameErr').show();
                parent.window.tip("请填写收货人姓名")
                return false;
            }
            if (phone == null || phone == '') {
                $('#phoneErr').show();
                parent.window.tip("请填写收货人电话")
                return false;
            }
            var radiobutton = $("[name='zt']:checked").val();
            if (radiobutton == '2') {
                if (fhSheng == null || fhSheng == '') {
                    $('#cityErr').show();
                    parent.window.tip("请选择省市")
                    return false;
                }
                if (fhShi == null || fhShi == '') {
                    $('#cityErr').show();
                    parent.window.tip("请选择省市")
                    return false;
                }
                if (address == null || address == '') {
                    $('#addressErr').show();
                    parent.window.tip("请填写收货地址")
                    return false;
                }
            }

            if (deliverLogisticsId == null || deliverLogisticsId == '' || deliverLogisticsId == '0') {
                $('#deliverLogistics_idErr').show();
                parent.window.tip("请选择发货物流")
                return false;
            }
            if (delinerWarehouseId == null || delinerWarehouseId == '' || delinerWarehouseId == '0') {
                $('#deliverWarehouseIdErr').show();
                parent.window.tip("请选择仓库")
                return false;
            }
            if (warehouseLocaltion == null || warehouseLocaltion == '' || warehouseLocaltion == '0') {
                $('#warehouseLocaltionErr').show();
                parent.window.tip("请选择库位")
                return false;
            }
            if (sendSLA == null || sendSLA == '') {
                $('#sendSLAErr').show();
                parent.window.tip("请选择发货SLA")
                return false;
            }

            //判断是否需要返件
            var isr = false;
            for (var i = 0; i < equipment.length; i++) {
                console.log("r:" + equipment[i].isReturn);
                if (equipment[i].isReturn == 2) {
                    isr = true;
                }
            }
            //如果需要返件，返件物流为必填项
            if (isr) {
                if (retrunLogistics == null || retrunLogistics == '' || retrunLogistics == '0') {
                    $('#retrun_logisticsErr').show()
                    parent.window.tip("请选择返件物流")
                    return false;
                }
            } else {
                $('#retrun_logisticsErr').hide()
            }


            if (equipment == "" || equipment == null) {
                parent.window.tip("请添加备件");
            } else {
                $.messager.confirm('确认信息', '确定要保存发货单吗?', function (event) {
                    if (event) {
                        $.ajax({
                            type: "POST",
                            data: {
                                'srCode': srCode,
                                'soCode': soCode,
                                'crCode': crCode,
                                'deliverType': deliverType,
                                'zt': zt,
                                'userName': userName,
                                'phone': phone,
                                'address': address,
                                'cinemaName': cinemaName,
                                'delinerWarehouseId': delinerWarehouseId,
                                'deliverLogisticsId': deliverLogisticsId,
                                'deliverDes': deliverDes,
                                'retrunLogistics': retrunLogistics,
                                'ztWarehouseId': ztWarehouseId,
                                'fhSheng': fhSheng,
                                'fhShi': fhShi,
                                'thProvince': thProvince,
                                'thShi': thShi,
                                'wlSla': wlSla,
                                'addressTh': addressTh,
                                'sendSLA': sendSLA,
                                'warehouseLocaltion': warehouseLocaltion,
                                'equipment': JSON.stringify(equipment)
                            },
                            url: "cbsDelinerController.do?doAdd",
                            dataType: "json",
                            beforeSend: function () {
                                lockmask(true);
                            },
                            success: function (data) {
                                parent.window.tip("添加成功");
                                setTimeout("  addOneTab('发货管理','cbsDelinerController.do?cbsDeliner');", 1000);
                                setTimeout("closetab('新建发货单')", 1000);
                            },
                            complete: function () {
                                lockmask(false);
                            }
                        })
                    }
                }).panel('move', {
                    top: 100
                })

            }


        }

        /*
        * 选择自提是显示自提仓库项
        * */
        function showZt() {
            $.ajax({
                url: "cbsServiceController.do?getWarehouse",
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    var warehouseHql = data.warehouseHql;
                    $("#warehouse").html("");
                    var html = "";
                    for (var i = 0; i < warehouseHql.length; i++) {
                        html += "<option value='" + warehouseHql[i].id + "' >" + warehouseHql[i].name + "</option>"
                    }
                    $("#warehouse").append(html);
                }
            });

            $('#ztTr').show();
            $('#shTr1').hide();
            $('#shTr2').hide();
        }

        /*
        * 不自提则隐藏自提仓库项
        * */
        function hideZt() {
            //alert("不自提")
            $('#ztTr').hide();
            $('#shTr1').show();
            $('#shTr2').show();
            // $('#shUser').show();
        }

        /*
       * 根据省获取电影院
       * */
        function getCinema() {
            var city = $("#city").val();
            //alert(city)
            $.ajax({
                type: "post",
                data: {"city": city},
                url: "cbsDelinerController.do?getCinema",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择影院--</option>";
                    for (i in tbs) {
                        console.log("tbs:" + tbs[i].name)
                        html += '<option  value=' + tbs[i].id + '>' + tbs[i].name + '</option>';
                    }
                    $("#cinemaName").html(html);
                }
            })
        }

        /*
        * 根据选取的影院自动填充收货地址
        * */
        function getCinemaAddress() {
            var cinemaid = $("#cinemaName").val();
            $.ajax({
                type: "post",
                data: {"cinemaid": cinemaid},
                url: "cbsDelinerController.do?getCinemaAddress",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    console.log("tbs:" + tbs.address)
                    $('#address').val(tbs.address)
                }
            })
        }

        function checkeNullPhone(obj) {
            var value = obj.value;
            if (value == null || value == '' || value == '0') {
                $('#phoneErr').show();
                $("#ifPhoe").hide();
            } else {
                $('#phoneErr').hide();
                var b = fChPhone(value);
                if (b == false) {
                    $("#ifPhoe").show();
                }
                if (b) {
                    $("#ifPhoe").hide();
                }
            }
        }

        function checkeNull(obj) {
            var value = obj.value;
            if (value == null || value == '' || value == '0') {
                $('#' + obj.id + 'Err').show();
                $("#ifPhoe").hide();
            } else {
                $('#' + obj.id + 'Err').hide();
                var b = fChPhone(value);
                if (b == false) {
                    $("#ifPhoe").show();
                }
                if (b) {
                    $("#ifPhoe").hide();
                }
            }
        }

        function fChPhone(phone) {
            var regex = /^1[3|4|5|8][0-9]\d{4,8}$/;
            return regex.test(phone);
        }

        function hideErr() {
            var value = $('#retrun_logistics').val()
            if (value != null && value != '' && value != '0') {
                $('#retrun_logisticsErr').hide()
            }
        }

        function hideItemErr(obj) {
            var str = obj.id.substring(0, 32);
            var value = obj.value;
            if (value != null && value != '') {
                $('#' + str + 'itemIdErr').hide()
            } else {
                $('#' + str + 'itemIdErr').show()
            }
        }


        /**
         * 获取自提仓库
         */
        function getWarehouseAddress() {
            var id = $("#warehouse").val();
            var type = 1;
            $.ajax({
                url: "cbsServiceController.do?getWarehouse",
                data: {
                    "type": type,
                    "id": id
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    var a = "";
                    var tstList = data.tstList;
                    var cbsWarehouse = data.cbsWarehouse;
                    if (tstList != null) {
                        for (var i = 0; i < tstList.length; i++) {
                            a += tstList[i][3];
                        }
                        a += cbsWarehouse.address;
                        $("#span1").text(a);
                    }
                }
            });
        }

    </script>
</head>
<body>
<div><span style="font-weight: bold;">关联信息</span></div>
<input id="isNewCreate" name="isNewCreate" type="hidden"/>

<table class="nobordertable noborder">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>SR:</label>
        </td>
        <td width="30%">
            <input type="text" id="srCode">
        </td>
        <td class="al_r" width="20%">
            <label>SO:</label>
        </td>
        <td width="30%">
            <input id="soCode"/>&emsp;
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>CR(CBS服务单号):</label>
        </td>
        <td width="30%">
            <input id="crCode"/>
        </td>
        <td class="al_r" width="20%">
            <label>发货单类型:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <select id="deliverType" onchange="checkeNull(this)">
                <option value="">--请选择发货单类型--</option>
            </select>
            <span id="deliverTypeErr" hidden="hidden" style="color: red;font-size: 10px">发货单类型不能为空</span>
        </td>
    </tr>
    </tbody>
</table>
<div class="line"></div>
<div><span style="font-weight: bold;">备件</span>&nbsp;&nbsp;
    <a class="easyui-linkbutton l-btn" id="addEquipmentBtn" onclick="addEquipment()">添加备件</a></div>
<div class="line"></div>
<div class="l-div" id="addEquipmentDiv">
    <%--备件信息--%>
</div>
<div><span style="font-weight: bold;">收货人</span></div>
<div class="line"></div>
<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>是否自提:</label>
        </td>
        <td colspan="3" id="isZt">
            <input type="radio" class="zt" name="zt" value="1" onclick="showZt()"> 是
            <input type="radio" class="zt" name="zt" value="2" checked="checked" onclick="hideZt()"> 否
        </td>
    </tr>
    <tr id="shUser">
        <td class="al_r" width="20%">
            <label>姓名:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <input id="userName" onkeyup="checkeNull(this)"/>&emsp;
            <span id="userNameErr" hidden="hidden" style="color: red;font-size: 10px">收货人姓名不能为空</span>
        </td>
        <td class="al_r" width="20%">
            <label>电话:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <input id="phone" onkeyup="checkeNull(this)"/>&emsp;
            <span id="phoneErr" hidden="hidden" style="color: red;font-size: 10px">收货人电话不能为空</span>
        </td>
    </tr>
    <tr id="shTr1">
        <td class="al_r" width="20%">
            <label>收货地址:<font color="red">*</font></label>
        </td>
        <td width="30%" colspan="3">
            <select style="width: auto;" id="sheng" onchange="getCity()">
            </select>
            <select style="width: auto;" id="city"
                    onchange="getLogisticsByCity();getCinema();checkeNull(this);getSelectedWarouse()">
                <option value="">--请选择城市--</option>
            </select>
            <span id="cityErr" hidden="hidden" style="color: red;font-size: 10px">省市不能为空</span>
            <input style="width:50%" maxlength="200" id="address" name="address" onkeyup="checkeNull(this)"/>&emsp;
            <span id="addressErr" hidden="hidden" style="color: red;font-size: 10px">收货地址不能为空</span>
        </td>
    </tr>
    <tr id="shTr2">
        <td class="al_r" width="20%">
            <label>影院名称:<font color="red">&nbsp;</font></label>
        </td>
        <td width="30%" colspan="3">
            <input id="cinemaName" style="width: 300px">
            <t:choose hiddenName="id" hiddenid="id" url="cbsDelinerController.do?sendChooseCm"
                      name="cinemaLists"
                      icon="icon-search" title="影院列表" textname="cinemaName" isclear="true" height="500px"
                      width="500px"/>
        </td>
    </tr>
    <tr id="ztTr" hidden="hidden">
        <td class="al_r"><label>自提仓库:<font color="red">*</font></label></td>
        <td colspan="3">
            <select id="warehouse" onchange="getWarehouseAddress()">
            </select>
            &nbsp;&nbsp;
            <span id="span1"></span>
        </td>
    </tr>
    </tbody>
</table>
<div><span style="font-weight: bold;">物流</span></div>
<div class="line"></div>
<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>物流:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <select id="deliverLogistics_id"
                    onchange="getSLA();getWarehouseByLogistics();getFhContacts();checkeNull(this);">
                <option value="0">--请选择物流--</option>
                <c:forEach items="${tsDepartList}" var="te">
                    <option value="${te.departname}">${te.departname}</option>
                </c:forEach>
            </select>
            &emsp;<span id="deliverLogistics_idErr" hidden="hidden" style="color: red;font-size: 10px">物流不能为空</span>
        </td>
        <td class="al_r" width="20%">
            <label>联系人:</label>
        </td>
        <td width="30%" id="fhLogisticsContacts">
            <%--张三&nbsp;18833333888&nbsp;1231231@qq.com--%>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>仓库:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <select id="deliverWarehouseId" onchange="getWarehouseContacts();checkeNull(this);getSLAByWarsoue()">
                <option value="0">--请选择仓库--</option>
                <c:forEach items="${cbsWarehouseEntityList}" var="ware">
                    <option value="${ware.id}">${ware.name}</option>
                </c:forEach>
            </select>
            &emsp;<span id="deliverWarehouseIdErr" hidden="hidden" style="color: red;font-size: 10px">仓库不能为空</span>
        </td>
        <td class="al_r" width="20%">
            <label>联系人:</label>
        </td>
        <td width="30%" id="warehouseContacts">
            <%--张三&nbsp;18833333888&nbsp;1231231@qq.com--%>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>物流承诺SLA:</label>
        </td>
        <td colspan="3">
            <span id="logisticsSLA"></span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>库位:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <select id="warehouseLocaltion" onchange="checkeNull(this)">
                <option value="0">请选择库位</option>
            </select>
            &emsp;<span id="warehouseLocaltionErr" hidden="hidden" style="color: red;font-size: 10px">库位不能为空</span>
        </td>
        <td class="al_r" width="20%">
            <label>发货SLA:<font color="red">*</font></label>
        </td>
        <td width="30%">
            <select id="sendSLA" onchange="checkeNull(this)">
                <option>--请选择发货SLA--</option>
            </select>
            &emsp;<span id="sendSLAErr" hidden="hidden" style="color: red;font-size: 10px">发货SLA不能为空</span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label>物流提货地址:</label>
        </td>
        <td colspan="3">
            <select style="width: auto;" id="thSheng" onchange="getThCity();">
                <%--<option>北京</option>--%>
            </select>
            <select style="width: auto;" id="thCity" class="city">
                <option value="">--请选择城市--</option>
            </select>
            <input id="thAddress" style="width: 350px" maxlength="200"/>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top"></td>
        <td colspan="3">
            <span style="color: red;">*仅限非物流仓库发货时填写</span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label>发货说明:</label>
        </td>
        <td colspan="3">
            <textarea style="width: 100%; height: 60px;" id="deliverDes" maxlength="255"></textarea>
        </td>
    </tr>
    </tbody>
</table>
<div><span style="font-weight: bold;">选择返件物流</span></div>
<div class="line"></div>
<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>物流:</label>
        </td>
        <td width="30%">
            <select id="retrun_logistics" onchange="getContacts();hideErr()">
                <option value="">--请选择物流--</option>
            </select>
            <span id="retrun_logisticsErr" style="font-size: 10px;color: red" hidden="hidden">请选择返件物流</span>
        </td>
        <td width="30%" id="retrunLogisticsContacts">
            <%--张三&nbsp;18833333888&nbsp;1231231@qq.com--%>
        </td>
    </tr>
    </tbody>
</table>
<div style="text-align: center;">
    <a href="#" class="easyui-linkbutton l-btn" onclick="addDeliver()">保存</a>
</div>
</body>
<script src="webpage/com/zybk/cbs_deliver/cbsDeliner.js"></script>


